part of _;

extension on RegisterPage {
  void controller_refreshCode() {
    setState(() => codeParams = null);
    yRun(() => setState(() => codeParams = textController_loginname.text.isEmpty ? null : "?loginname=${textController_loginname.text}&t=${DateTime.now().microsecond}"));
  }

  void controller_register() {
    if (!isSelectProtocol) {
      yToast("请阅读并同意协议");
      return;
    }
    var loginname = textController_loginname.text;
    if (loginname.isEmpty) {
      yToast(hint_loginname);
      return;
    }
    var password1 = textController_password1.text;
    if (password1.isEmpty) {
      yToast(hint_password1);
      return;
    }
    var password2 = textController_password2.text;
    if (password2.isEmpty) {
      yToast(hint_password2);
      return;
    }
    var code = textController_code.text;
    if (code.isEmpty) {
      yToast(hint_code);
      return;
    }
    yPost<UserModel>(IFinal.Jkids.register, {
      "loginname": loginname,
      "password": EncodeUtils.encodePassword(password1),
      "code": code,
    }, (isSuccess, results, code, message) {
      if (isSuccess) {
        yToast("注册成功，请登录");
        yIntent(LoginPage(loginname: loginname), intentType: YIntentType.Present_Replace);
      } else {
        controller_refreshCode();
      }
    }, onModel: (map) => UserModel.fromJson(map));
  }
}
